package com.haoshuang.zhouzhoubang.ui.dialog

import android.content.Context
import androidx.recyclerview.widget.LinearLayoutManager
import com.haoshuang.zhouzhoubang.R
import com.haoshuang.zhouzhoubang.databinding.DialogServiceItemBinding
import com.haoshuang.zhouzhoubang.databinding.ItemServiceItemBinding
import com.haoshuang.zhouzhoubang.model.bean.OrderGoodsBean
import com.lxj.xpopup.core.BottomPopupView
import com.mufeng.libs.base.BaseBindingHolder
import com.mufeng.libs.base.BaseBindingQuickAdapter
import com.mufeng.libs.utils.view.click

class ShowServiceItemDialog(
    context: Context,
    private val orderGoodsList: MutableList<OrderGoodsBean>
) : BottomPopupView(context) {

    override fun getImplLayoutId(): Int {
        return R.layout.dialog_service_item
    }

    private lateinit var binding: DialogServiceItemBinding

    private val adapter = ServiceItemAdapter(orderGoodsList)

    override fun onCreate() {
        super.onCreate()
        binding = DialogServiceItemBinding.bind(popupImplView)
        binding?.tvServiceNum?.text = "（共"+orderGoodsList.size+"项服务）"

        binding.recyclerView.layoutManager =
            LinearLayoutManager(context, LinearLayoutManager.VERTICAL, false)
        binding.recyclerView.adapter = adapter

        binding?.tvGb?.click {
            dismiss()
        }

        binding?.tvKnow?.click {
            dismiss()
        }
    }
}

class ServiceItemAdapter(data: MutableList<OrderGoodsBean>) :
    BaseBindingQuickAdapter<OrderGoodsBean, ItemServiceItemBinding>(data) {

    override fun onBindViewHolder(holder: BaseBindingHolder, position: Int, item: OrderGoodsBean?) {
        val binding = ItemServiceItemBinding.bind(holder.itemView)

        binding.tvGoodsName.text = item?.goods_name
        binding.tvProductAttrName.text = item?.product_attr_name
        binding.tvNum.text = "x" + item?.num.toString()
        binding.tvMoney.text = "¥" + item?.money
    }
}